/*
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.

Anser:906609
Time:29.076957ms
*/
package main

import (
	"fmt"
	"strconv"
	"time"
)

func main() {
	tstart := time.Now()
	m, n := 0, 0
	for i := 100; i < 1000; i++ {
		for j := 100; j < 1000; j++ {
			if i%10 != 0 && j%10 != 0 {
				n = i * j
				if Palindromic(strconv.Itoa(n)) {
					m = Max(m, n)
				}
			}
		}
	}
	fmt.Println(m)
	tend := time.Now()
	fmt.Println(tend.Sub(tstart))
}

// Palindromic 判断是否是回文数
func Palindromic(s string) bool {
	lenth := len(s)
	if lenth < 2 {
		return true
	}
	if s[0] == s[lenth-1] {
		return Palindromic(s[1 : lenth-1])
	}
	return false
}

// Max 比较大小
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
